package com.zenithmind.task.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 任务优先级枚举
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Getter
@AllArgsConstructor
public enum TaskPriority {

    /**
     * 低优先级
     */
    LOW(1, "低", "low", "#52c41a"),

    /**
     * 中等优先级
     */
    MEDIUM(2, "中", "medium", "#1890ff"),

    /**
     * 高优先级
     */
    HIGH(3, "高", "high", "#fa8c16"),

    /**
     * 紧急
     */
    URGENT(4, "紧急", "urgent", "#f5222d");

    /**
     * 优先级码
     */
    private final Integer code;

    /**
     * 优先级名称
     */
    private final String name;

    /**
     * 优先级标识
     */
    private final String key;

    /**
     * 显示颜色
     */
    private final String color;

    /**
     * 根据优先级码获取枚举
     * 
     * @param code 优先级码
     * @return 任务优先级枚举
     */
    public static TaskPriority getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (TaskPriority priority : values()) {
            if (priority.getCode().equals(code)) {
                return priority;
            }
        }
        return null;
    }

    /**
     * 根据优先级标识获取枚举
     * 
     * @param key 优先级标识
     * @return 任务优先级枚举
     */
    public static TaskPriority getByKey(String key) {
        if (key == null) {
            return null;
        }
        for (TaskPriority priority : values()) {
            if (priority.getKey().equals(key)) {
                return priority;
            }
        }
        return null;
    }

    /**
     * 检查是否为高优先级（高或紧急）
     * 
     * @return 是否高优先级
     */
    public boolean isHighPriority() {
        return this == HIGH || this == URGENT;
    }

    /**
     * 检查是否为紧急优先级
     * 
     * @return 是否紧急
     */
    public boolean isUrgent() {
        return this == URGENT;
    }

    /**
     * 获取优先级权重（用于排序）
     * 
     * @return 权重值
     */
    public int getWeight() {
        return this.code;
    }
}
